package com.xunyin.utils;


import com.xunyin.exception.BadRequestException;
import com.xunyin.modules.security.security.vo.JwtUser;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 获取用户登录信息
 */
public class JwtUserUtils {

    /**
     * 获取系统用户的所管辖店铺Id
     *
     * @return 系统用户的所管辖店铺Id
     */
    public static JwtUser getUserInfo() {
        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null) {
            throw new BadRequestException(HttpStatus.UNAUTHORIZED, "当前登录状态过期");
        }
        JwtUser jwtUser = (JwtUser) authentication.getPrincipal();
        return jwtUser;
    }
}
